import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
// import { dictItemCheck } from './api';
// import { rules } from '/@/utils/helper/validator';
import { h } from 'vue';

export const columns: BasicColumn[] = [
  // {
  //   title: '名称',
  //   dataIndex: 'title',
  //   width: 240,
  // },
  {
    title: '配置页面',
    dataIndex: 'confType_dictText',
    width: 100,
    // customRender: ({ text }) => {
    //   const types = ['首页', '列表页', '详情页'];
    //   return types[text] || '';
    // },
  },
  {
    title: '跳转类型',
    dataIndex: 'type_dictText',
    width: 100,
    // customRender: ({ text }) => {
    //   const types = ['网页', '小程序'];
    //   return types[text] || '';
    // },
  },
  {
    title: '链接',
    dataIndex: 'link',
    width: 240,
  },
  {
    title: '图片',
    dataIndex: 'img',
    width: 120,
    customRender: ({ text }) => {
      return h('img', {
        src: `${import.meta.env.VITE_GLOB_ONLINE_VIEW_URL}${text}`,
        style: {
          width: '32px',
          height: '32px',
          objectFit: 'cover',
        },
      });
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ text }) => {
      return text == '1' ? '开启' : '关闭';
    },
  },
];

export const recycleBincolumns: BasicColumn[] = [
  {
    title: '字典名称',
    dataIndex: 'title',
    width: 120,
  },
  {
    title: '字典编码',
    dataIndex: 'icon',
    width: 120,
  },
  {
    title: '描述',
    dataIndex: 'path',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '菜单名称',
    field: 'title',
    component: 'JInput',
    colProps: { span: 6 },
  },
  {
    label: '状态',
    field: 'status',
    component: 'Select',
    componentProps: {
      options: [
        { label: '开启', value: '1' },
        { label: '关闭', value: '0' },
      ],
    },
    colProps: { span: 6 },
  },
  {
    label: '配置类型',
    field: 'confType',
    component: 'Select',
    componentProps: {
      options: [
        { label: '首页', value: '0' },
        { label: '列表页', value: '1' },
        { label: '详情页', value: '2' },
      ],
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  // {
  //   label: '名称',
  //   field: 'title',
  //   required: true,
  //   component: 'Input',
  // },
  {
    label: '配置页面',
    field: 'confType',
    component: 'Select',
    defaultValue: '0',
    required: true,
    componentProps: {
      options: [
        { label: '首页', value: '0' },
        { label: '列表页', value: '1' },
        { label: '详情页', value: '2' },
      ],
    },
  },
  {
    label: '跳转类型',
    field: 'type',
    component: 'Select',
    defaultValue: '1',
    required: true,
    componentProps: {
      options: [
        { label: '小程序', value: '0' },
        { label: '网页', value: '1' },
      ],
    },
  },
  {
    label: '链接',
    field: 'link',
    component: 'Input',
    required: true,
    componentProps: {
      fileMax: 1,
    },
  },
  {
    label: 'appId',
    field: 'appId',
    component: 'Input',
    // required: true,
  },
  {
    label: '图片',
    field: 'img',
    required: true,
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
    },
  },

  {
    label: '状态',
    field: 'status',
    component: 'RadioButtonGroup',
    defaultValue: '1',
    componentProps: {
      options: [
        { label: '开启', value: '1' },
        { label: '关闭', value: '0' },
      ],
    },
  },
];

export const dictItemColumns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'itemText',
    width: 80,
  },
  {
    title: '数据值',
    dataIndex: 'itemValue',
    width: 80,
  },
  {
    title: '字典颜色',
    dataIndex: 'itemColor',
    width: 80,
    align: 'center',
    customRender: ({ text }) => {
      return h('div', {
        style: { background: text, width: '18px', height: '18px', 'border-radius': '50%', margin: '0 auto' },
      });
    },
  },
];

export const dictItemSearchFormSchema: FormSchema[] = [
  {
    label: '名称',
    field: 'itemText',
    component: 'Input',
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'dict_item_status',
      stringToNumber: true,
    },
  },
];

export const itemFormSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '名称',
    field: 'itemText',
    required: true,
    component: 'Input',
  },

  {
    label: '颜色值',
    field: 'itemColor',
    component: 'Input',
    slot: 'itemColor',
  },
  {
    label: '描述',
    field: 'description',
    component: 'Input',
  },
  {
    field: 'sortOrder',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 1,
  },
  {
    field: 'status',
    label: '是否启用',
    defaultValue: 1,
    component: 'JDictSelectTag',
    componentProps: {
      type: 'radioButton',
      dictCode: 'dict_item_status',
      stringToNumber: true,
    },
  },
];
